package com.sxt.sys.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.sys.SYSConstast.SYSConstast;
import com.sxt.sys.domain.Dept;
import com.sxt.sys.domain.Permission;
import com.sxt.sys.mapper.PermissionMapper;
import com.sxt.sys.service.PermissionService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.vo.PermissionVo;
@Service
public class PermissionServiceImpl implements PermissionService{
	@Autowired
	private PermissionMapper permissionMapper;
	
	
	
	@Override
	public List<Permission> queryAllPermisson(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.qureyAllPermission(permissionVo);
	}

	@Override
	public List<Permission> queryApartPermissonByUserId(Integer userId) {
		
		return permissionMapper.queryApartPermissonByUserId(SYSConstast.MENU_TYPE_MENU,userId);
	}

	

	@Override
	public DataGridView qureyAllPermissionByMenu(PermissionVo permissionVo) {
		Page<Object> page = PageHelper.startPage(permissionVo.getPage(),permissionVo.getLimit());
		List<Permission> data = permissionMapper.qureyAllPermissionByMenu(permissionVo);
		return new DataGridView(page.getTotal(),data);
	}

	@Override
	public List<Permission> queryAllPermissionForlist(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.qureyAllPermission(permissionVo);
	}

	@Override
	public Integer deletePermission(Integer id) {
		// TODO Auto-generated method stub
		return permissionMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Integer addPermission(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		permissionVo.setOrdernum(permissionVo.getOrdernum()+1);
		
		return permissionMapper.insertSelective(permissionVo);
	}

	@Override
	public Integer updatePermission(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.updateByPrimaryKeySelective(permissionVo);
	}

	@Override
	public Integer queryMaxOrderNumber() {
		// TODO Auto-generated method stub
		return permissionMapper.loadMaxOrderNumber();
	}

	@Override
	public Integer isThisPermissionObjHasChildren(Integer id) {
		// TODO Auto-generated method stub
		return permissionMapper.queryByIdChildrend(id);
	}

	@Override
	public DataGridView queryAllPermissionByTypePermission(PermissionVo permissionVo) {
		Page<Object> page = PageHelper.startPage(permissionVo.getPage(),permissionVo.getLimit());
		List<Permission> data = permissionMapper.queryAllPermissionByTypePermission(permissionVo);
		return new DataGridView(page.getTotal(),data);
	}

	@Override
	public List<Permission> queryPermissionByRoleId(Integer id) {
		// TODO Auto-generated method stub
		return permissionMapper.queryPermissionByRoleId(id);
	}

	@Override
	public List<String> queryPermissionByUserIdForStrList(Integer id) {
		List<String> data=new ArrayList<>();
		List<Permission> all = permissionMapper.queryPermissionByUserId(SYSConstast.MENU_TYPE_PERMISSION,id);
		for (Permission permission : all) {
			data.add(permission.getPercode());
		}
		return data;
	}

}
